using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using TMPro;

public class MainMenu : MonoBehaviour
{   
    [SerializeField] private TextMeshProUGUI helloText;

    private void Start() {
        string tempText = "Hello, ";
        if (PlayerPrefs.HasKey("nickname") && PlayerPrefs.GetString("nickname").Length > 1) {
            tempText += PlayerPrefs.GetString("nickname");
            if (PlayerPrefs.HasKey("second_nickname") && PlayerPrefs.GetString("second_nickname").Length > 1) {
                tempText = tempText + " & " + PlayerPrefs.GetString("second_nickname") + "!";
            } else {
                tempText += "!";
                PlayerPrefs.SetString("second_nickname", "Player2");
            }
        } else {
            tempText += "Player!";
            PlayerPrefs.SetString("nickname", "Player1");
            PlayerPrefs.SetString("second_nickname", "Player2");
        }
        
        helloText.text = tempText;
    }

    public void PlayGameSingle() {
        PlayerPrefs.SetInt("playersCount", 1); 
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    }

    public void PlayGameMultiPlayer() {
        PlayerPrefs.SetInt("playersCount", 2); 
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    }

    public void ExitGame() { Application.Quit(); }

}
